package me.goldze.mvvmhabit.binding.viewadapter.viewpager;

import android.databinding.BindingAdapter;
import android.support.v4.view.ViewPager;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class ViewAdapter {
    @BindingAdapter(requireAll = false, value = {"onPageScrolledCommand", "onPageSelectedCommand", "onPageScrollStateChangedCommand"})
    public static void onScrollChangeCommand(ViewPager viewPager, final BindingCommand<ViewPagerDataWrapper> onPageScrolledCommand, final BindingCommand<Integer> onPageSelectedCommand, final BindingCommand<Integer> onPageScrollStateChangedCommand) {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            /* class me.goldze.mvvmhabit.binding.viewadapter.viewpager.ViewAdapter.AnonymousClass1 */
            private int state;

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                BindingCommand bindingCommand = onPageScrolledCommand;
                if (bindingCommand != null) {
                    bindingCommand.execute(new ViewPagerDataWrapper((float) position, positionOffset, positionOffsetPixels, this.state));
                }
            }

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageSelected(int position) {
                BindingCommand bindingCommand = onPageSelectedCommand;
                if (bindingCommand != null) {
                    bindingCommand.execute(Integer.valueOf(position));
                }
            }

            @Override // android.support.v4.view.ViewPager.OnPageChangeListener
            public void onPageScrollStateChanged(int state2) {
                this.state = state2;
                BindingCommand bindingCommand = onPageScrollStateChangedCommand;
                if (bindingCommand != null) {
                    bindingCommand.execute(Integer.valueOf(state2));
                }
            }
        });
    }

    public static class ViewPagerDataWrapper {
        public float position;
        public float positionOffset;
        public int positionOffsetPixels;
        public int state;

        public ViewPagerDataWrapper(float position2, float positionOffset2, int positionOffsetPixels2, int state2) {
            this.positionOffset = positionOffset2;
            this.position = position2;
            this.positionOffsetPixels = positionOffsetPixels2;
            this.state = state2;
        }
    }
}
